<template>
    <div class="icons">
        <swiper :options="swiperOption" >
            <swiper-slide v-for="(page,index) of pages" :key="index" >
                <div class="icon" v-for="item of page" :key="item.id" >
                    <div class="icon-img">
                        <img class="icon-img-content" :src="item.imgUrl"/>
                    </div>
                    <p class="icon-desc">{{item.img_desc}}</p>
                </div>
            </swiper-slide>
            <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
    </div>
</template>
<script>
export default {
  name: 'HomeIcons',
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        autoplay: false
      },
      iconList: [{
        id: '001',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
        img_desc: '热门景点'
      }, {
        id: '002',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/3e/86314b2af03b7502.png',
        img_desc: '水上乐园'
      }, {
        id: '003',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/ff/fdf170ee89594b02.png',
        img_desc: '必游榜单'
      }, {
        id: '004',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/95/8d02011d149bdb02.png',
        img_desc: '成都定制'
      }, {
        id: '005',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/97/02f5043b51b2102.png',
        img_desc: '情迷九寨'
      }, {
        id: '006',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/20/831d62d2e1c7be02.png',
        img_desc: '蓉城七景'
      }, {
        id: '007',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/b6/37560ece9c62b502.png',
        img_desc: '成都周边'
      }, {
        id: '008',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/ed/cf572be30fc32f02.png',
        img_desc: 'Q+精选'
      }, {
        id: '009',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/e3/67df61427c8e1302.png',
        img_desc: '演出'
      }, {
        id: '010',
        imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/80/416c6ab3368d1f02.png',
        img_desc: '全部玩乐'
      }
      ]
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }

}
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl'
@import '~styles/mixins.styl'
.icons>>> .swiper-container
  height: 0
  padding-bottom: 50%
.icons>>>.swiper-pagination-bullet-active
  background :#69c
.icons
  margin-top .1rem
  .icon
    position :relative
    overflow :hidden
    float :left
    width :25%
    height :0
    padding-bottom :25%
    .icon-img
      position :absolute
      top:0
      left :0
      right :0
      bottom :.44rem
      box-sizing :border-box
      padding :.1rem
      .icon-img-content
        display :block
        margin 0 auto
        height :100%
    .icon-desc
      position :absolute
      left :0
      right :0
      bottom 0
      height :.44rem
      line-height  :.44rem
      color :$icon-desctext-color
      text-align center
      ellipsis()
</style>
